package com.zhf.controller;

import com.zhf.domain.*;
import com.zhf.service.MenuService;
import com.zhf.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: ZhaoHuanfeng
 * @Date: 2020/12/5 13:14
 */
@RestController
@RequestMapping("/role")
public class RoleController {


    @Autowired
    private RoleService roleService;

    /*
    查询所有角色
     */
    @RequestMapping("/findAllRole")
    public ResponseResult findAllRole(@RequestBody Role role){
        List<Role> roles = roleService.findAllRole(role);

        ResponseResult result = new ResponseResult(true, 200, "查询所有角色成功", roles);
        return result;
    }

    @Autowired
    private MenuService menuService;

    /*
    查询所有父子菜单信息
     */
    @RequestMapping("/findAllMenu")
    public ResponseResult findSubMenuListByPid(){
        List<Menu> menuList = menuService.findSubMenuListByPid(-1);
        HashMap<String, Object> map = new HashMap<>();
        map.put("parentMenuList",menuList);
        ResponseResult result = new ResponseResult(true, 200, "响应成功", map);
        return result;
    }

    /*
    根据角色id查询关联的菜单信息
     */
    @RequestMapping("/findMenuByRoleId")
    public ResponseResult findMenuByRoleId(Integer roleId){
        List<Integer> menu = roleService.findMenuByRoleId(roleId);

        ResponseResult result = new ResponseResult(true, 200, "查询角色关联的菜单信息成功", menu);
        return result;
    }

    /*
    为角色分配菜单
     */
    @RequestMapping("/RoleContextMenu")
    public ResponseResult roleContextMenu(@RequestBody RoleMenuVo roleMenuVo) {
        roleService.roleContextMenu(roleMenuVo);
        ResponseResult result = new ResponseResult(true, 200, "响应成功", null);
        return result;
    }

    /*
    删除角色
     */
    @RequestMapping("/deleteRole")
    public ResponseResult deleteRole(int id){
        roleService.deleteRole(id);
        ResponseResult result = new ResponseResult(true, 200, "删除角色成功", null);
        return result;
    }
}
